package com.zito.health.service.impl;

import com.zito.health.entity.Extension;
import com.zito.health.entity.ExtensionTrain;
import com.zito.health.mapper.ExtensionMapper;
import com.zito.health.mapper.ExtensionTrainMapper;
import com.zito.health.service.ExtensionService;
import com.zito.health.vo.ExtensionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Sam on 2020/03/12.
 */
@Service
public class ExtensionServiceImpl implements ExtensionService {

    @Autowired
    private ExtensionMapper extensionMapper;
    @Autowired
    private ExtensionTrainMapper extensionTrainMapper;

    @Override
    public Extension save(Extension object) {
        extensionMapper.insert(object);
        return object;
    }

    @Override
    public void delete(Integer id) {
        extensionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Extension object) {
        extensionMapper.updateByPrimaryKeySelective(object);
    }

    @Override
    public List<Extension> query() {
        return extensionMapper.selectAll();
    }

    @Override
    public List<Extension> query(Extension object) {
        return extensionMapper.select(object);
    }

    @Override
    public Extension queryOne(Extension object) {
        return extensionMapper.selectOne(object);
    }

    @Override
    public Extension queryById(Integer id) {
        return extensionMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean exists(Integer id) {
        return false;
    }

    @Override
    public List<Extension> queryList(Extension param) {
        List<Extension> extensionList = extensionMapper.queryList(param);
        if(extensionList != null && extensionList.size()>0){
            for(int i=0;i<extensionList.size();i++){
                ExtensionTrain extensionTrain = new ExtensionTrain();
                extensionTrain.setExtensionId(extensionList.get(i).getId());
                List<ExtensionTrain> extensionTrainList = extensionTrainMapper.select(extensionTrain);
                extensionList.get(i).setSchedules(Integer.toString(extensionTrainList.size()));
            }
        }
        return extensionList;
    }

    @Override
    public List<ExtensionVo> queryListForTrack(Extension param) {
        List<ExtensionVo> list = extensionMapper.queryListForTrack(param);

        List listid = new ArrayList();

        String huiyi="";

        for(int i=0;i<list.size();i++){
            //人员对负责人打分
            list.get(i).setDoubleOne(extensionMapper.selectPingjunfen(list.get(i).getId()));
            //培训得分
            list.get(i).setDoubleTwo(extensionMapper.selectPingjunfen1(list.get(i).getId()));
            //培训人员对项目打分
            list.get(i).setDoubleThree(extensionMapper.selectPingjunfen2(list.get(i).getId()));

//            if(extensionTrainService.selectByExtensionId(list.get(i).getId()).size()>0){
//                /*list.get(i).setPingjunfen(leExtensionService.selectPingjunfen(list.get(i).getId()));*/
//                List<LeExtensionTrain> listhui = leExtensionTrainService.selectByExtensionId(list.get(i).getId());
//                for(int j=0;j<listhui.size();j++){
//                    huiyi+=listhui.get(j).getTitle()+"; ";
//                    list.get(i).setHuiyi(huiyi);
//                }
//                huiyi="";
//            }else{
//
//            }

        }
        return list;
    }

    @Override
    public List<Extension> queryListForAssessment(Extension param) {
        return extensionMapper.queryListForAssessment(param);
    }
}
